﻿@using SH = EMoney.IStock.Client.Framework.StringHelper;
@using EMoney.IStock.Client.Models.QQ;

@{
    Layout = null;


    string apply = ViewBag.Apply;

    Assets assets = ViewBag.Assets;

    decimal total_zc = 0;
    decimal total_sz = 0;
    decimal cangwei = 0;
    decimal yinkui = 0;
    decimal yinkui_bl = 0;
    decimal cash_assets = 0;// 995161.00m;
    string rankIndex = string.Empty;
    string rankDayIndex = string.Empty;
    string rankWeekIndex = string.Empty;

    if (assets != null && assets.data != null)
    {
        total_zc = Convert.ToDecimal(assets.data.total_zc);
        total_sz = Convert.ToDecimal(assets.data.total_sz);
        cash_assets = Convert.ToDecimal(assets.data.cash_assets);
        cangwei = Convert.ToDecimal(assets.data.cangwei);
        yinkui = Convert.ToDecimal(assets.data.yinkui);
        yinkui_bl = yinkui / 1000000 * 100;
        rankIndex = assets.data.rankIndex;
        rankDayIndex = assets.data.rankDayIndex;
        rankWeekIndex = assets.data.rankWeekIndex;
    }
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>我的大赛</title>
    <link href="@SH.GetStaticFile("IStockClientStatic/css/jquery.autocomplete.css")" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" type="text/css" href="@ViewBag.PageCss" id="linkcss" />
    <link rel="stylesheet" type="text/css" href="@ViewBag.ScrollCss" id="linkscrollcss" />

    <script src="http://static.emoney.cn/js/libs/jquery.min.1.8.3.js" type="text/javascript"></script>
    <script src="~/IStockClientStatic/My97DatePicker/WdatePicker.js"></script>
</head>
<body>
    <div class="clear"></div>
    <div class="main">
        <!--account-->
        <div class="account">
            <div class="account_left">
                <h3><a href="javascript:;" style="cursor:default;" hidefocus="true">
                    <img src="@SH.GetStaticFile("IStockClientStatic/qq/images/account_bg01.png")" /></a></h3>
                <p>我的模拟盘账户</p>
            </div>
            <div class="account_center">
                <ul>
                    <li><span>总资产：</span><b class="account_center_font01 fz18 red" id="totalzc">@SH.FormatDecimal(total_zc)</b></li>
                    <li><span>可用资金：</span><b id="cashassets">@SH.FormatDecimal(cash_assets)</b></li>
                    <li><span>浮动盈亏：</span><span class="@SH.FormatQQColor(yinkui)" id="yingkui">@SH.FormatDecimal(yinkui)</span></li>
                    <li>
                        <p class="account_center_red btnbuy" style="cursor:pointer;"><a href="javascript:;" hidefocus="true">买入</a></p>
                    </li>
                </ul>
                <ul>
                    <li><span>总市值：</span><b class="account_center_font01 fz18 red" id="totalsz">@SH.FormatDecimal(total_sz)</b></li>
                    <li><span>当前仓位：</span><b id="cangwei">@SH.FormatDecimal(cangwei)%</b></li>
                    <li><span>盈亏比例：</span><span class="@SH.FormatQQColor(yinkui_bl)" id="yingkuibi">@SH.FormatDecimal(yinkui_bl)%</span></li>
                    <li>
                        <p class="btnsell" style="cursor:pointer;"><a href="javascript:;" hidefocus="true">买出</a></p>
                    </li>
                </ul>
            </div>
            <div class="account_right">
                <ul>
                    <li><span>总排名：</span><b class="red" id="rankindex">@rankIndex@*<em>↓</em>*@</b></li>
                    <li><span>周排名：</span><b class="red" id="rankweekindex">@rankWeekIndex@*<em class="green">↑</em>*@</b></li>
                    <li><span>日排名：</span><b class="red" id="rankdayindex">@rankDayIndex@*<em>↑</em>*@</b></li>
                </ul>
            </div>
        </div>
        <!--account end-->
        <div class="mege_main" style="height: auto;">
            <div class="tc_loading" id="tc_loading" style="display: none">数据加载中...</div>
            <div class="mask" id="tc_mask" style="display: none"></div>
            <div class="time" style="display: none; color: #999;">开始时间： <a hidefocus="true" href="javascript:;" class="date" id="start" onfocus="WdatePicker({isShowClear:false,isShowOK:false,readOnly:true,onpicking:function(dp){if(dp.cal.getNewDateStr() != dp.cal.getDateStr()){querydealorders(dp.cal.getNewDateStr(),'');}}})">@ViewBag.Start</a> 结束时间： <a hidefocus="true" href="javascript:;" class="date" id="end" onfocus="WdatePicker({isShowClear:false,isShowOK:false,readOnly:true,onpicking:function(dp){if(dp.cal.getNewDateStr() != dp.cal.getDateStr()){querydealorders('',dp.cal.getNewDateStr());}}})">@ViewBag.End</a></div>
            <div class="tab_1"><a hidefocus="true" href="javascript:;" class="on" flag="1">我的持仓</a><a hidefocus="true" href="javascript:;" flag="2">待撤单</a><a hidefocus="true" href="javascript:;" flag="3">当日成交</a><a hidefocus="true" href="javascript:;" flag="5">历史成交</a></div>
            <div class="rank_k" style="height: auto;">
            </div>
        </div>
    </div>
    <div class="trading" id="trading" style="display: none;">
        <div class="close"></div>
        <div class="top_bar" style="text-align: left;">买入</div>
        <div class="lpart">
            <p class="stock_name" style="text-align: left;">&nbsp;</p>
            <div class="tradk">
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                        <td>证券代码：</td>
                        <td colspan="2">
                            <input type="text" name="textfield" id="txtCode" class="ipt1" /></td>
                    </tr>
                    <tr>
                        <td>委托价格：</td>
                        <td colspan="2">
                            <input type="text" name="textfield" id="txtPrice" class="ipt1" /></td>
                    </tr>
                    <tr id="trUsable">
                        <td>可用资金：</td>
                        <td colspan="2" style="text-align: left;"><span class="red fz16 usable">@cash_assets</span></td>
                    </tr>
                    <tr>
                        <td width="66"><span id="spanMaxNum">最大可买：</span></td>
                        <td width="85" style="text-align: left;"><span class="red fz16 maxnum"></span></td>
                        <td width="49" align="right"><a hidefocus="true" href="javascript:;" class="btn5" flag="1">全部</a></td>
                    </tr>
                    <tr>
                        <td colspan="3"><a hidefocus="true" href="javascript:;" class="percent" flag="5">1/5</a> <a hidefocus="true" href="javascript:;" class="percent" flag="4">1/4</a> <a hidefocus="true" href="javascript:;" class="percent" flag="3">1/3</a> <a hidefocus="true" href="javascript:;" class="percent" flag="2">1/2</a></td>
                    </tr>
                    <tr>
                        <td><span id="spanNum">买入数量：</span></td>
                        <td colspan="2">
                            <input type="text" name="textfield" id="txtNum" class="ipt1" /></td>
                    </tr>
                </table>
            </div>
        </div>
        <div class="rpart">
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr class="bb1">
                    <td width="25%" align="center">委比</td>
                    <td width="25%" align="left"><span id="wb"></span></td>
                    <td width="25%" align="left">委差</td>
                    <td width="25%" align="left"><span id="wc"></span></td>
                </tr>
                <tr>
                    <td align="center">卖五</td>
                    <td align="left"><span id="sp5" class="p" title="点击设置委托价格"></span></td>
                    <td align="left"><span id="sn5"></span></td>
                    <td align="left">&nbsp;&nbsp;&nbsp;</td>
                </tr>
                <tr>
                    <td align="center">卖四</td>
                    <td align="left"><span id="sp4" class="p" title="点击设置委托价格"></span></td>
                    <td align="left"><span id="sn4"></span></td>
                    <td align="left"></td>
                </tr>
                <tr>
                    <td align="center">卖三</td>
                    <td align="left"><span id="sp3" class="p" title="点击设置委托价格"></span></td>
                    <td align="left"><span id="sn3"></span></td>
                    <td align="left"></td>
                </tr>
                <tr>
                    <td align="center">卖二</td>
                    <td align="left"><span id="sp2" class="p" title="点击设置委托价格"></span></td>
                    <td align="left"><span id="sn2"></span></td>
                    <td align="left"></td>
                </tr>
                <tr class="bb1">
                    <td align="center">卖一</td>
                    <td align="left"><span id="sp1" class="p" title="点击设置委托价格"></span></td>
                    <td align="left"><span id="sn1"></span></td>
                    <td align="left"><span></span></td>
                </tr>
                <tr class="bb1">
                    <td align="center">最新</td>
                    <td align="left"><span id="p" class="p" title="点击设置委托价格"></span></td>
                    <td align="left"><span id="d"></span></td>
                    <td align="left"><span id="f"></span></td>
                </tr>
                <tr>
                    <td align="center">买一</td>
                    <td align="left"><span id="bp1" class="p" title="点击设置委托价格"></span></td>
                    <td align="left"><span id="bn1"></span></td>
                    <td align="left"></td>
                </tr>
                <tr>
                    <td align="center">买二</td>
                    <td align="left"><span id="bp2" class="p" title="点击设置委托价格"></span></td>
                    <td align="left"><span id="bn2"></span></td>
                    <td align="left"></td>
                </tr>
                <tr>
                    <td align="center">买三</td>
                    <td align="left"><span id="bp3" class="p" title="点击设置委托价格"></span></td>
                    <td align="left"><span id="bn3"></span></td>
                    <td align="left"></td>
                </tr>
                <tr>
                    <td align="center">买四</td>
                    <td align="left"><span id="bp4" class="p" title="点击设置委托价格"></span></td>
                    <td align="left"><span id="bn4"></span></td>
                    <td align="left"></td>
                </tr>
                <tr>
                    <td align="center">买五</td>
                    <td align="left"><span id="bp5" class="p" title="点击设置委托价格"></span></td>
                    <td align="left"><span id="bn5"></span></td>
                    <td align="left"></td>
                </tr>
            </table>
        </div>
        <div class="clear"></div>
        <div id="divMsg" class="red" style="text-align: left; line-height: 20px; padding-left: 25px;">&nbsp;</div>
        <div class="btn_k1" style="padding-top: 0px;"><a hidefocus="true" href="javascript:;" class="btn6" style="font-size: 14px;">买 入</a> <a hidefocus="true" href="javascript:;" class="btn7" style="font-size: 14px;">重 置</a></div>
    </div>
    <div class="popuptrade" id="popup" style="display: none;">
        <h3><span>交易提示</span><b id="popup_close"></b></h3>
        <ul>
            <li>操作类型：<span class="popup_font" id="popup_type"></span></li>
            <li>股票代码：<span id="popup_stock"></span></li>
            <li>委托价格：<span id="popup_price"></span></li>
            <li>委托数量：<span id="popup_number"></span></li>
            <li>委托金额：<span id="popup_amount"></span></li>
        </ul>
        <p style="width: 220px; display: block; padding-left: 20px;" class="red" id="tradeConfirm"></p>
        <p><a hidefocus="true" href="javascript:;" class="popup_unselect_B">取消</a><a hidefocus="true" href="javascript:;" class="popup_unselect_A">确认</a></p>
    </div>
    
    <script type="text/javascript" src="@SH.GetStaticFile("IStockClientStatic/js/jquery.autocomplete.pack.js")"></script>
    <script type="text/javascript" src="@SH.GetStaticFile("IStockClientStatic/js/istockfunc.js")"></script>
    <script type="text/javascript" src="@SH.GetStaticFile("IStockClientStatic/js/jquery.blockUI.js")"></script>
    <script src="@SH.GetStaticFile("IStockClientStatic/js/EMWEBUIscrollBar.js")" type="text/javascript"></script>
    @*<script src="@SH.GetStaticFile("IStockClientStatic/js/jquery.tablesorter.js")" type="text/javascript"></script>*@
    <script type="text/javascript" src="http://static.emoney.cn/www/js/StockJS2.js"></script>

    <input type="hidden" id="hidApply" value="@apply" />
    <input type="hidden" id="hidCash" value="@cash_assets" />
    <input type="hidden" id="hidStart" value="@ViewBag.Start"/>
    <input type="hidden" id="hidEnd" value="@ViewBag.End"/>
    <input type="hidden" id="hidWhiteCss" value="@SH.GetStaticFile("IStockClientStatic/qq/css/white.css")" />
    <input type="hidden" id="hidBlackCss" value="@SH.GetStaticFile("IStockClientStatic/qq/css/black.css")" />
    <input type="hidden" id="hidScrollWhiteCss" value="@SH.GetStaticFile("IStockClientStatic/css/scroll.css")" />
    <input type="hidden" id="hidScrollBlackCss" value="@SH.GetStaticFile("IStockClientStatic/css/scrollblock.css")" />
</body>
</html>
<script type="text/javascript">
    var winH = 0, www = "@Url.Content("~/")", cash = $("#hidCash").val(), apply = $("#hidApply").val(), curtab = "", bs = "",
        percent = "0", start = $("#hidStart").val(), end = $("#hidEnd").val(), hidStocks = "", hidSellList = "", klinestocks = "", cancelid = "", cancelcode = "";

    //document.onselectstart = function () { return true; }
    //document.onmousemove = function (e) { return true; }

    $(document).ready(function () {
        winH = $(window).height(), winW = $(window).width();

        //$(".rank_k").height(winH - $(".mege_top").height() - $(".tab_1").height() - 20);        

        $(window).bind('load resize', '', function () {
            $(document).queue(function () {
                $(document).dequeue();
                var winH = $(window).height(), winW = $(window).width();

                $(".rank_k").height(winH - $(".account").height() - $(".tab_1").height() - 40);
            });
        });

        $(".p").css("cursor", "pointer");

        $(".p").click(function () {
            var p = $(this).html();

            if (p != undefined && p != "") {
                $("#txtPrice").val(p);
                $("#txtPrice").change();
            }
        });

        $(".btnbuy").click(function () {  //买入
            reset();

            bs = "buy";
            $("#trUsable").show();
            $("#spanMaxNum").html("最大可买：");
            $("#spanNum").html("买入数量：");
            $(".btn6").html("买 入");
            $(".top_bar").html("买入");

            var left = (document.body.clientWidth - 478) / 2;
            var top = (document.body.clientHeight - 380) / 2;

            $.blockUI({ message: $('#trading'), css: { top: top, left: left, width: '478' } });
        });

        $(".btnsell").click(function () {  //卖出
            reset();

            bs = "sell";
            $("#trUsable").hide();
            $("#spanMaxNum").html("最大可卖：");
            $("#spanNum").html("卖入数量：");
            $(".btn6").html("卖 出");
            $(".top_bar").html("卖出");

            var left = (document.body.clientWidth - 478) / 2;
            var top = (document.body.clientHeight - 380) / 2;

            $.blockUI({ message: $('#trading'), css: { top: top, left: left, width: '478' } });
        });

        $(".btn5").click(function () {  //全部
            $(".percent").removeClass("on");
            initnum($(this).attr("flag"));
        });

        $(".close").click(function () {
            $.unblockUI();
            $(".blockUI").fadeOut("slow");

            ISTOCK_FUNC_TRADES("");
        });

        $(".percent").click(function () {
            if ($(".maxnum").html() != undefined && $(".maxnum").html() != "" && $(".maxnum").html() != "0") {
                initnum($(this).attr("flag"));

                $(".percent").removeClass("on");
                $(this).addClass("on");
            }
        });

        $(".btn6").click(function () {
            $("#divMsg").html("&nbsp;");

            var name = $(".stock_name").html();
            var code = $("#txtCode").val();
            var price = $("#txtPrice").val();
            var num = $("#txtNum").val();
            var maxnum = $(".maxnum").html();

            if (name == "") {
                $("#divMsg").html("请选择股票");
                $("#txtCode").focus();
            }
            else if (code == "") {
                $("#divMsg").html("请选择股票");
                $("#txtCode").focus();
            }
            else if (name.split("-")[1] != code) {
                $("#divMsg").html("选择的股票有误");
                $("#txtCode").focus();
            }
            else if (price == "") {
                $("#divMsg").html("请输入价格");
                $("#txtPrice").focus();
            }
            else if (num == "") {
                $("#divMsg").html("请输入数量");
                $("#txtNum").focus();
            }
            else if (isNaN(num)) {
                $("#divMsg").html("数量格式错误");
            }
            else if (bs == "buy" && parseInt(num) % 100 > 0) {
                $("#divMsg").html("数量请输入100的整数");
                $("#txtNum").focus();
            }
            else if (parseInt(num) > parseInt(maxnum)) {
                $("#divMsg").html("不能大于最大数");
                $("#txtNum").focus();
            }
            else {
                var type = "";
                switch (bs) {
                    case "buy":
                        type = "买入";
                        break;
                    case "sell":
                        type = "卖出";
                        break;
                    default:
                        break;
                }

                $(".btn6").hide();
                $(".btn7").hide();
                $(".close").hide();

                $("#popup_type").html(type);
                $("#popup_stock").html($(".stock_name").html());
                $("#popup_price").html(formatFloat($("#txtPrice").val()));
                $("#popup_number").html($("#txtNum").val());

                var amount = formatFloat(formatFloat($("#txtPrice").val()) * formatFloat($("#txtNum").val()));

                $("#popup_amount").html(amount);

                $("#tradeConfirm").html("");

                $(".popup_unselect_A").show();
                $("#popup").show();
            }
        });

        $(".popup_unselect_A").click(function () {
            if (cancelid == "") { //委买、委卖
                $.ajax({
                    type: "post",
                    url: www + "qq/addorder",
                    data: { code: $("#popup_stock").html().split("-")[1], bs: bs, p: $("#popup_price").html(), c: $("#popup_number").html() },
                    datatype: "data",
                    success: function (data) {
                        if (data == "0") {
                            $("#tradeConfirm").html("委托成功");

                            setTimeout("$('#popup_close').click();", 1000);

                            $(".percent").removeClass("on");
                            $("#txtNum").val("");
                            assets("0");
                        }
                        else {
                            $("#tradeConfirm").html(data);
                            $(".popup_unselect_A").show();
                        }
                    },
                    beforeSend: function () {
                        $("#tradeConfirm").html("委托中...");
                        $(".popup_unselect_A").hide();
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        $("#tradeConfirm").html(XMLHttpRequest.status);
                    }
                });
            }
            else {  //撤单
                $.ajax({
                    type: "post",
                    url: www + "qq/docancelorder",
                    data: { oid: cancelid, code: cancelcode },
                    datatype: "html",
                    success: function (data) {
                        if (data == "0") {
                            $("#tradeConfirm").html("撤单成功");
                            cancelid = "";

                            setTimeout("reloadCancelOrder()", 1000);
                            assets("0");
                        }
                        else {
                            $("#tradeConfirm").html(data);

                            $(".popup_unselect_A").show();
                        }
                    },
                    beforeSend: function () {
                        $("#tradeConfirm").html("撤单中...");
                        $(".popup_unselect_A").hide();
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        $("#tradeConfirm").html(XMLHttpRequest.status);
                    }
                });
            }
        });

        $("#popup_close").click(function () {
            $(".btn6").show();
            $(".btn7").show();
            $(".close").show();
            $("#popup").hide();
        });

        $(".popup_unselect_B").click(function () {
            $("#popup_close").click();
        });

        $(".btn7").click(function () {
            reset();
        });

        $("#txtPrice").change(function () {
            if (bs == "buy") {
                maxnum($(this).val());

                initnum(percent);
            }
        });

        $(".rank_k").delegate('.buy', 'click', '', function () {
            var code = $(this).attr("code");
            var name = $(this).attr("name");

            if (code != undefined && code != "") {
                $(".btnbuy").click();

                $("#txtCode").val(code);
                $(".stock_name").html(name + "-" + code);

                ISTOCK_FUNC_TRADES(code);
            }
        });

        $(".rank_k").delegate('.sell', 'click', '', function () {
            var code = $(this).attr("code");
            var name = $(this).attr("name");

            if (code != undefined && code != "") {
                $(".btnsell").click();

                $("#txtCode").val(code);
                $(".stock_name").html(name + "-" + code);

                ISTOCK_FUNC_TRADES(code);

                $(".maxnum").html($(this).attr("sellnumber"));
            }
        });

        $(".rank_k").delegate('.cancelorder', 'click', '', function () {
            var price = $(this).attr("price");
            var count = $(this).attr("count");

            cancelid = $(this).attr("uuid");
            cancelcode = $(this).attr("code");

            $("#popup_type").html("撤单");
            $("#popup_stock").html($(this).attr("name") + "-" + $(this).attr("code"));
            $("#popup_price").html(price);
            $("#popup_number").html(count);

            var amount = parseInt(formatFloat(price) * formatFloat(count));

            $("#popup_amount").html(amount);

            $("#tradeConfirm").html("");

            $(".popup_unselect_A").show();
            $("#popup").show();
        });

        //$(".rank_k").delegate('.stock', 'mouseenter', '', function () {
        //    $(this).css("text-decoration", "underline");
        //});
        //$(".rank_k").delegate('.stock', 'mouseleave', '', function () {
        //    $(this).css("text-decoration", "none");
        //});
        //$(".rank_k").delegate('.stock', 'click', '', function () {
        $(".rank_k").delegate('tr ', 'dblclick', '', function () {
            GroupToKLine("我的大赛", $(this).attr("code"), klinestocks);
        });

        $("#txtCode").autocomplete(
        EALists, {
            max: 9,
            minChars: 1,
            width: 155,
            matchContains: true,
            autoFill: false,
            selectFirst: true,
            formatItem: function (row, i, max) {
                return row.C + " " + row.S + " " + row.N;
            },
            formatMatch: function (row, i, max) {
                return row.C + " " + row.S + " " + row.N;
            },
            formatResult: function (row) {
                return row.C;
            }
        }).result(function (event, row, formatted) {
            if (row.C != null) {
                $(".stock_name").html(row.N + "-" + row.C);
                $("#txtCode").val(row.C);
                //quotes(row.C);

                ISTOCK_FUNC_TRADES(row.C);

                if (bs == "sell") {
                    var sellnumber = 0;
                    var selllist = hidSellList;

                    if (selllist != "") {
                        var obj = eval(selllist);

                        if (obj != null && obj.length > 0) {

                            $.each(obj, function (i) {
                                if (obj[i].C == row.C) {
                                    sellnumber = obj[i].N;
                                    return false;
                                }
                            });
                        }
                    }

                    $(".maxnum").html(sellnumber);
                }
            }
        });

        $(".tab_1 a").click(function () {
            var flag = $(this).attr("flag");

            if (flag != curtab) {
                var url = "";
                $(".time").hide();

                $(".tab_1 a").removeClass("on");
                $(this).addClass("on");

                switch (flag) {
                    case "1":
                        url = www + "qq/stocks";
                        break;
                    case "2":
                        url = www + "qq/cancelorder";
                        break;
                    case "3":
                        url = www + "qq/dealorders";
                        break;
                    case "5":
                        $(".time").show();
                        url = www + "qq/dealorders?start=" + start + "&end=" + end;
                        break;
                    default:
                        break;
                }

                if (url != "") {
                    $.ajax({
                        type: "post",
                        url: url,
                        data: {},
                        datatype: "html",
                        success: function (data) {
                            $(".rank_k").html(data);
                            //$(".rank_list").height($(".rank_k").height() - 34);

                            $("#tc_loading").hide();
                            $("#tc_mask").hide();

                            switch (flag) {
                                case "1":
                                    ISTOCK_FUNC_QUOTES(hidStocks);
                                    break;
                                default:
                                    break;
                            }

                            $(".scrollBox").jscroll({ W: "8px", IW: "8px", CurrT: 0, Bar: { Pos: "up" }, Btn: { btn: false }, Fn: function () { } }).hover(function (e) {
                                var thisbx = $(this), scrlbr = $(this).find(".jscroll-e");
                                if (!scrlbr.hasClass("non")) {
                                    scrlbr.addClass("mon").stop(true, true, false).show();
                                }
                            }, function (e) {
                                var thisbx = $(this), scrlbr = $(this).find(".jscroll-e");
                                if (!scrlbr.hasClass("non")) {
                                    scrlbr.removeClass("mon");
                                    if (scrlbr.hasClass("vxdrag")) { } else {
                                        //scrlbr.fadeOut("slow");
                                    }
                                }
                            });
                            //alert(winH + " " + $(".mege_top").height() + " " + $(".tab_1").height() + " " + 20);
                            $("#scrollBox1").height(winH - $(".account").height() - $(".tab_1").height() - 75);

                            ReSetScroll();

                            //$("#tblist").tablesorter();

                            //var $sortTab = $("#tblist"), $clkTab0 = $("#tbsorter"), $sortTab_th = $("tr th", $sortTab), $clkTab0_th = $("tr th", $clkTab0), $clknum0;

                            //$clkTab0_th.click(function () {
                            //    try {
                            //        $clknum0 = $clkTab0_th.index(this);
                            //        $sortTab_th.eq($clknum0).click();
                            //    } catch (e) {
                            //        alert(e.message);
                            //    }

                            //});
                        },
                        beforeSend: function () {
                            $("#tc_loading").show();
                            $("#tc_mask").show();
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            //alert(XMLHttpRequest.status);
                            $("#tc_loading").hide();
                            $("#tc_mask").hide();
                        }
                    });
                }

                curtab = flag;
            }
        });

        $(".tab_1 a")[0].click();

        setTimeout("assets()", 1000 * 60);
    });

    function assets(flag) {
        $.post(www + "QQ/assets", {  }, function (data) {
            if (data != "") {
                var obj = eval('(' + data + ')');

                if (obj != null && obj.data != null && obj.code == "0") {
                    $("#totalzc").html(obj.data.total_zc);
                    $("#cashassets").html(obj.data.cash_assets);

                    $("#yingkui").removeClass("red");
                    $("#yingkui").removeClass("green");
                    $("#yingkui").html(obj.data.yinkui); //class
                    $("#yingkui").addClass(colorcss(formatFloat(obj.data.yinkui),0));

                    $("#totalsz").html(obj.data.total_sz);
                    $("#cangwei").html(obj.data.cangwei + "%");

                    $("#yingkuibi").removeClass("red");
                    $("#yingkuibi").removeClass("green");

                    var ykb = formatFloat(formatFloat(obj.data.yinkui) / 1000000 * 100);
                    $("#yingkuibi").html(ykb + "%");      //class
                    $("#yingkuibi").addClass(colorcss(formatFloat(ykb), 0));

                    $("#rankindex").html(obj.data.rankIndex);
                    $("#rankweekindex").html(obj.data.rankWeekIndex);
                    $("#rankdayindex").html(obj.data.rankDayIndex);
                }
            }
        })

        if (flag != "0") {
            setTimeout("assets()", 1000 * 60);
        }
    }

    function reloadCancelOrder() {
        $('#popup').hide();
        curtab = "";
        $('.tab_1 a')[1].click();
    }

    function querydealorders(s, e) {
        if (s != undefined && s != "") {
            start = s;
        }
        if (e != undefined && e != "") {
            end = e;
        }

        curtab = "";
        $(".tab_1 a")[3].click();
    }

    function formatStockcode(stockcode) {
        if (stockcode != undefined && stockcode != "") {
            if (stockcode.indexOf("sh") > -1) {
                stockcode = stockcode.replace("sh", "");
            }
            else if (stockcode.indexOf("sz") > -1) {
                stockcode = stockcode.replace("sz", "");
            }

            return stockcode;
        }
        else {
            return "";
        }
    }

    function ISTOCK_FUNC_QUOTES_CALLBACK(data) {
        //alert(data);
        //data = "{\"data\":[{\"c\":\"29.44\",\"code\":1000156,\"p\":\"---\",\"zdf\":\"---\"},{\"c\":\"4.77\",\"code\":600317,\"p\":\"---\",\"zdf\":\"---\"},{\"c\":\"10.09\",\"code\":1000001,\"p\":\"---\",\"zdf\":\"---\"},{\"c\":\"3.40\",\"code\":600017,\"p\":\"---\",\"zdf\":\"---\"},{\"c\":\"12.15\",\"code\":1002650,\"p\":\"---\",\"zdf\":\"---\"},{\"c\":\"13.90\",\"code\":1002340,\"p\":\"---\",\"zdf\":\"---\"},{\"c\":\"38.95\",\"code\":600600,\"p\":\"---\",\"zdf\":\"---\"},{\"c\":\"12.76\",\"code\":1002423,\"p\":\"---\",\"zdf\":\"---\"},{\"c\":\"158.46\",\"code\":600519,\"p\":\"---\",\"zdf\":\"---\"}],\"ver\":1}";
        if (data != undefined && data != "" && curtab == "1") {
            var obj = eval('(' + data + ')');

            if (obj != null && obj.data != null && obj.data.length > 0) {
                $.each(obj.data, function (i) {
                    if (obj.data[i].code != undefined && obj.data[i].code != "") {  // && obj.data[i].p != "---"
                        obj.data[i].code = obj.data[i].code + "";
                        if (obj.data[i].code.substring(0, 1) == "1") {
                            obj.data[i].code = obj.data[i].code.substring(1, obj.data[i].code.length);
                        }

                        var price = 0;
                        //最新价
                        if (obj.data[i].p != "---") {
                            price = obj.data[i].p;
                            $("#tblist tbody tr[code=" + obj.data[i].code + "]").children('td').eq(3).html("<span class=" + colorcss(obj.data[i].zdf, 0) + ">" + obj.data[i].p + "</span>");
                            //涨跌幅
                            $("#tblist tbody tr[code=" + obj.data[i].code + "]").children('td').eq(4).html("<span class=" + colorcss(obj.data[i].zdf, 0) + ">" + obj.data[i].zdf + "</span>");
                        }
                        else {
                            price = obj.data[i].c;
                        }
                        
                        //持股数
                        var number = $("#tblist tbody tr[code=" + obj.data[i].code + "]").children('td').eq(5).html();
                        //成本价
                        var cost = $("#tblist tbody tr[code=" + obj.data[i].code + "]").children('td').eq(7).text();
                        
                        $("#tblist tbody tr[code=" + obj.data[i].code + "]").children('td').eq(7).html("<span class=" + colorcss(price, cost) + ">" + cost + "</span>");
                        //持仓市值
                        $("#tblist tbody tr[code=" + obj.data[i].code + "]").children('td').eq(8).html(formatFloat(price * parseInt(number)));
                        //浮动盈亏
                        var fdyk = (formatFloat(price) - formatFloat(cost)) * parseInt(number);
                        $("#tblist tbody tr[code=" + obj.data[i].code + "]").children('td').eq(9).html("<span class=" + colorcss(fdyk, 0) + ">" + formatFloat(fdyk) + "</span>");
                        //盈亏比
                        var ykb = (formatFloat(price) - formatFloat(cost)) / formatFloat(cost) * 100;
                        $("#tblist tbody tr[code=" + obj.data[i].code + "]").children('td').eq(10).html("<span class=" + colorcss(ykb, 0) + ">" + formatFloat(ykb) + "%</span>");
                    }
                });
            }
        }
    }

    function ISTOCK_FUNC_TRADES_CALLBACK(data) {
        //alert(data);
        if (data != undefined && data != "") {
            var obj = eval('(' + data + ')');

            if (obj != null && obj.data != null && obj.data.length > 0) {
                //alert($("#txtCode").val() + " " + obj.data[0].code);
                if (obj.data[0].code.toString().indexOf($("#txtCode").val()) > -1) {
                    var y = obj.data[0].c;

                    if ($("#txtPrice").val() == "") {
                        if (obj.data[0].p != 0) {
                            $("#txtPrice").val(formatFloat(obj.data[0].p));

                            $("#txtPrice").change();
                        }
                    }

                    $("#sp5").html(formatFloat(obj.data[0].ps5));
                    $("#sn5").html(obj.data[0].vs5);
                    $("#sp4").html(formatFloat(obj.data[0].ps4));
                    $("#sn4").html(obj.data[0].vs4);
                    $("#sp3").html(formatFloat(obj.data[0].ps3));
                    $("#sn3").html(obj.data[0].vs3);
                    $("#sp2").html(formatFloat(obj.data[0].ps2));
                    $("#sn2").html(obj.data[0].vs2);
                    $("#sp1").html(formatFloat(obj.data[0].ps1));
                    $("#sn1").html(obj.data[0].vs1);

                    $("#bp5").html(formatFloat(obj.data[0].pb5));
                    $("#bn5").html(obj.data[0].vb5);
                    $("#bp4").html(formatFloat(obj.data[0].pb4));
                    $("#bn4").html(obj.data[0].vb4);
                    $("#bp3").html(formatFloat(obj.data[0].pb3));
                    $("#bn3").html(obj.data[0].vb3);
                    $("#bp2").html(formatFloat(obj.data[0].pb2));
                    $("#bn2").html(obj.data[0].vb2);
                    $("#bp1").html(formatFloat(obj.data[0].pb1));
                    $("#bn1").html(obj.data[0].vb1);

                    $("#p").html(formatFloat(obj.data[0].p));
                    $("#d").html(formatFloat(obj.data[0].zd));
                    $("#f").html(formatFloat(obj.data[0].zdf) + "%");

                    $("#wb").html(obj.data[0].weibi);
                    $("#wc").html(obj.data[0].weicha);

                    $(".rpart span").removeClass("red");
                    $(".rpart span").removeClass("green");

                    $("#sp5").addClass(colorcss(obj.data[0].ps5, y));
                    $("#sp4").addClass(colorcss(obj.data[0].ps4, y));
                    $("#sp3").addClass(colorcss(obj.data[0].ps3, y));
                    $("#sp2").addClass(colorcss(obj.data[0].ps2, y));
                    $("#sp1").addClass(colorcss(obj.data[0].ps1, y));
                    $("#bp5").addClass(colorcss(obj.data[0].pb5, y));
                    $("#bp4").addClass(colorcss(obj.data[0].pb4, y));
                    $("#bp3").addClass(colorcss(obj.data[0].pb3, y));
                    $("#bp2").addClass(colorcss(obj.data[0].pb2, y));
                    $("#bp1").addClass(colorcss(obj.data[0].pb1, y));

                    $("#p").addClass(colorcss(obj.data[0].p, y));
                    $("#d").addClass(colorcss(obj.data[0].zd, 0));
                    $("#f").addClass(colorcss(obj.data[0].zdf, 0));
                }
            }
        }
    }

    function maxnum(p) {
        if (p != undefined && p != "") {
            p = formatFloat(p);

            if (p > 0) {
                var maxnum = formatFloat(cash) / p;

                if (maxnum >= 100) {
                    $(".maxnum").html(parseInt(maxnum / 100) * 100);
                }
                else {
                    $(".maxnum").html("0");
                }
            }
        }
    }

    function initnum(percentFlag) {
        if (percentFlag == "0") {
            return false;
        }

        percent = percentFlag;
        var maxnum = $(".maxnum").html();

        if (maxnum != undefined && maxnum != "" && maxnum != "0") {
            var percentnum = formatFloat(maxnum) / formatFloat(percent);

            if (percentnum >= 100) {
                $("#txtNum").val(parseInt(percentnum / 100) * 100);
            }
            else {
                $("#txtNum").val("0");
            }
        }
    }

    function quotes(code) {
        $.ajax({
            type: "post",
            url: www + "qq/quotes",
            data: { code: code },
            datatype: "text",
            success: function (data) {
                if (data != "") {
                    var obj = eval('(' + data + ')');

                    if (obj != null && obj.length > 0) {
                        var y = obj[0].Y;

                        $("#txtPrice").val(formatFloat(obj[0].P));

                        $("#txtPrice").change();

                        $("#sp5").html(formatFloat(obj[0].SP5));
                        $("#sn5").html(obj[0].SV5);
                        $("#sp4").html(formatFloat(obj[0].SP4));
                        $("#sn4").html(obj[0].SV4);
                        $("#sp3").html(formatFloat(obj[0].SP3));
                        $("#sn3").html(obj[0].SV3);
                        $("#sp2").html(formatFloat(obj[0].SP2));
                        $("#sn2").html(obj[0].SV2);
                        $("#sp1").html(formatFloat(obj[0].SP1));
                        $("#sn1").html(obj[0].SV1);

                        $("#bp5").html(formatFloat(obj[0].BP5));
                        $("#bn5").html(obj[0].BV5);
                        $("#bp4").html(formatFloat(obj[0].BP4));
                        $("#bn4").html(obj[0].BV4);
                        $("#bp3").html(formatFloat(obj[0].BP3));
                        $("#bn3").html(obj[0].BV3);
                        $("#bp2").html(formatFloat(obj[0].BP2));
                        $("#bn2").html(obj[0].BV2);
                        $("#bp1").html(formatFloat(obj[0].BP1));
                        $("#bn1").html(obj[0].BV1);

                        $("#p").html(formatFloat(obj[0].P));
                        $("#d").html(formatFloat(obj[0].D));
                        $("#f").html(formatFloat(obj[0].F) + "%");

                        $(".rpart span").removeClass("red");
                        $(".rpart span").removeClass("green");

                        $("#sp5").addClass(colorcss(obj[0].SP5, y));
                        $("#sp4").addClass(colorcss(obj[0].SP4, y));
                        $("#sp3").addClass(colorcss(obj[0].SP3, y));
                        $("#sp2").addClass(colorcss(obj[0].SP2, y));
                        $("#sp1").addClass(colorcss(obj[0].SP1, y));
                        $("#bp5").addClass(colorcss(obj[0].BP5, y));
                        $("#bp4").addClass(colorcss(obj[0].BP4, y));
                        $("#bp3").addClass(colorcss(obj[0].BP3, y));
                        $("#bp2").addClass(colorcss(obj[0].BP2, y));
                        $("#bp1").addClass(colorcss(obj[0].BP1, y));

                        $("#p").addClass(colorcss(obj[0].P, y));
                        $("#d").addClass(colorcss(obj[0].P, y));
                        $("#f").addClass(colorcss(obj[0].P, y));
                    }
                }
            },
            beforeSend: function () {
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert(XMLHttpRequest.status);
            }
        });
    }

    function reset() {
        $(".stock_name").html("&nbsp;");
        $("#txtCode").val("");
        $("#txtPrice").val("");
        $(".maxnum").html("");
        $(".percent").removeClass("on");
        $("#txtNum").val("");
        $(".rpart span").html("&nbsp;");
        $(".usable").html(cash);
        $("#txtNum").val("");
        $("#divMsg").html("&nbsp;");
        percent = "0";

        ISTOCK_FUNC_TRADES("");
    }

    function colorcss(d1, d2) {
        d1 = d1 + "";
        if (d1.indexOf("%") > -1) {
            d1 = d1.replace("%", "");
        }

        d1 = formatFloat(d1);
        d2 = formatFloat(d2);

        if (d1 > d2) {
            return "red";
        }
        else if (d1 < d2) {
            return "green";
        }
        else {
            return "";
        }
    }

    function formatFloat(v, f) {
        try {
            v = v + "";
            if (v.indexOf("--") != -1) {
                return v;
            }
            if (v.indexOf("%") > -1) {
                v = v.replace("%", "");
            }
            if (f == undefined || f == "") {
                f = 2;
            }
            return parseFloat(v).toFixed(f);
        } catch (e) {
            return 0;
        }
    }

    function OnSkinChanged(skinName) {
        var cssHref = "";
        var scrollCssHref = "";

        switch (skinName) {
            case "default":
                hidColor = skinName;
                cssHref = $("#hidWhiteCss").val();
                scrollCssHref = $("#hidScrollWhiteCss").val();
                break;
            case "black":
                hidColor = skinName;
                cssHref = $("#hidBlackCss").val();
                scrollCssHref = $("#hidScrollBlackCss").val();
                break;
            default:
                break;
        }

        if (cssHref != "") {
            $("#linkcss").attr("href", cssHref);
            $("#linkscrollcss").attr("href", scrollCssHref);
        }
    }
</script>
